package es.efor.ics.gev.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.*;

@Entity
@Table(name = "ATRIBUTOS_ACCIONES_BIS")
@AssociationOverrides({
@AssociationOverride(name = "pk.accion", joinColumns = @JoinColumn(name = "accion_id")),
@AssociationOverride(name = "pk.atributo", joinColumns = @JoinColumn(name = "atributo_id"))
})
public class AtributoAccionBis implements Serializable {
    
    /**
     * 
     */
    private static final long serialVersionUID = 989493303129930692L;

    @Embeddable
    public static class AtributoAccionPk implements Serializable {

	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -3056952221294420968L;
	private Accion accion;
	private AtributoMaestro atributo;

	@ManyToOne(fetch = FetchType.LAZY)
	public Accion getAccion() {
	    return accion;
	}

	public void setAccion(Accion accion) {
	    this.accion = accion;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	public AtributoMaestro getAtributo() {
	    return atributo;
	}

	public void setAtributo(AtributoMaestro atributo) {
	    this.atributo = atributo;
	}

	public boolean equals(Object o) {
	    if (this == o)
		return true;
	    if (o == null || getClass() != o.getClass())
		return false;

	    AtributoAccionPk that = (AtributoAccionPk) o;

	    if (atributo != null ? !atributo.equals(that.atributo) : that.atributo != null)
		return false;
	    if (accion != null ? !accion.equals(that.accion)
		    : that.accion != null)
		return false;

	    return true;
	}

	public int hashCode() {
	    int result;
	    result = (atributo != null ? atributo.hashCode() : 0);
	    result = 31 * result + (accion != null ? accion.hashCode() : 0);
	    return result;
	}

    }
    
    private AtributoAccionPk pk = new AtributoAccionPk();  
    private Integer count;
    
    public AtributoAccionBis() {	
    }

    public AtributoAccionBis(AtributoMaestro atrib, Accion acc) {
	setAtributo(atrib);
	setAccion(acc);
	setCount(0);
    }   

    @Column(name = "count")
    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }
    
    @EmbeddedId
    public AtributoAccionPk getPk() {
        return pk;
    }

    public void setPk(AtributoAccionPk pk) {
        this.pk = pk;
    }
    
    @Transient
    public AtributoMaestro getAtributo() {
	return pk.getAtributo();
    }
    
    public void setAtributo(AtributoMaestro atributo) {
	getPk().setAtributo(atributo);
    }
    
    @Transient
    public Accion getAccion() {
	return pk.getAccion();
    }
    
    public void setAccion(Accion accion) {
	getPk().setAccion(accion);
    }
    
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
 
        AtributoAccionBis that = (AtributoAccionBis) o;
 
        if (getPk() != null ? !getPk().equals(that.getPk()) : that.getPk() != null) return false;
 
        return true;
    }
 
    public int hashCode() {
        return (getPk() != null ? getPk().hashCode() : 0);
    }

    
    

}
